import {BasicColumn, FormSchema} from '/@/components/Table';
import {DescItem} from '/@/components/Description/index';
import {render} from '/@/utils/common/renderUtils';

export const MaterialType = {
  IMAGE: { type: 'image', name: '图片' },
  VOICE: { type: 'voice', name: '音频' },
  VIDEO: { type: 'video', name: '视频' },
};

export const columns : BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'url',
    slots: { customRender: 'media' },
    width: 240,
    align: 'left'
  },
  {
    title: '大小',
    dataIndex: 'size',
    customRender: ({ text }) => {
      return render.renderSpan(text + ' KB')
    },
    width: 80,
  },
  {
    title: '创建时间',
    dataIndex: 'createdAt',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '',
    component: 'Input',
    componentProps: {
      placeholder: '搜索媒体',
    }
  },
];


export const formDetailSchema : DescItem[] = [
  {
    field: 'bizType',
    label: '业务类型',
  },
  {
    field: 'bucketName',
    label: '存储桶'
  },
  {
    field: 'storageType',
    label: '存储器',
    render: (curVal, data) => {
      return render.renderTag(render.renderDict(curVal, 'file_storage_type'), 'green')
    }
  },
  {
    field: 'originalName',
    label: '文件原始名称'
  },
  {
    label: '新文件名',
    labelMinWidth: 50,
    field: 'newName',
  },
  {
    field: 'fileTypeName',
    label: '文件类型'
  },
  {
    field: 'fileSize',
    label: '文件大小',
    render: (curVal, data) => {
      return render.renderTag(curVal + ' KB', 'green')
    },
  },
  {
    field: 'filePath',
    label: '存储绝对路径'
  },
  {
    field: 'createdAt',
    label: '创建时间'
  },
  {
    field: 'createdBy',
    label: '创建者'
  }
];


export const materialGroupFormSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'name',
    label: '分组名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'parentId',
    label: '上级分组',
    component: 'TreeSelect',
    required: false,
    componentProps: {
      fieldNames: {
        title: 'name',
        key: 'id',
        value: 'id',
      },
      dropdownStyle: {
        maxHeight: '60vh'
      },
      getPopupContainer: (node) => node.parentNode
    },
  },
  {
    field: 'sortNo',
    label: '排序',
    required: true,
    component: 'InputNumber',
    defaultValue: 1
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        minRows: 3,
        maxRows: 8
      }
    }
  },
];


export const materialFormSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'url',
    required: true,
    component: 'JUpload',
    label: '媒体文件'
  },
  {
    field: 'groupId',
    label: '分组',
    component: 'TreeSelect',
    required: false,
    componentProps: {
      fieldNames: {
        title: 'name',
        key: 'id',
        value: 'id',
      },
      dropdownStyle: {
        maxHeight: '60vh'
      },
      getPopupContainer: (node) => node.parentNode
    },
  },
  
];
